package com.pumpkin.asyncdemo.component;


import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public abstract class AbstractTask {

    public static Random random = new Random();

    public void doTaskOne(String name) throws InterruptedException, ExecutionException {
        System.out.println("开始做任务一");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(1000));
        Thread.sleep(5000);
        long end = System.currentTimeMillis();
        System.out.println("完成任务一：耗时：" + (end -start) + "毫秒" + name);
    }

    public void doTaskTwo() throws InterruptedException, ExecutionException {
        System.out.println("开始做任务二");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(1000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务二：耗时：" + (end -start) + "毫秒");
    }

    public void doTaskThree() throws InterruptedException, ExecutionException {
        System.out.println("开始做任务三");
        long start = System.currentTimeMillis();
        Thread.sleep(random.nextInt(1000));
        long end = System.currentTimeMillis();
        System.out.println("完成任务三：耗时：" + (end -start) + "毫秒");
    }
}
